package com.yunfeng.supercall.activity;

import java.io.IOException;

import org.json.JSONException;
import org.json.JSONObject;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Bitmap;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnPreparedListener;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.lin.action.UIDfineAction;
import com.lin.utils.Parameters;
import com.lin.utils.Session;
import com.lin.utils.Session.ResultReceiver;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.display.PinterestCircleBitmapDisplayer;
import com.yunfeng.supercall.R;
import com.yunfeng.supercall.activity.BaseCallActivity.CallStateReceiver;
import com.yunfeng.supercall.bean.Constants;
import com.yunfeng.supercall.bean.ContactsBaseBean;
import com.yunfeng.supercall.bean.SuperFriendsBean;
import com.yunfeng.supercall.httputils.MyAjaxCallBack;
import com.yunfeng.supercall.service.CallConnectionService;
import com.yzx.api.CallType;
import com.yzx.api.ClientType;
import com.yzx.api.UCSCall;
import com.yzx.api.UCSMessage;
import com.yzx.api.UCSService;
import com.yzx.tcp.packet.UcsStatus;
import com.yzx.tools.CustomLog;

public class OutCallActivity extends BaseCallActivity {
	//*******************
//	private LinearLayout remotelayout,locallayout;



	private SuperFriendsBean mSuperFriends;
	private TextView mTextView;

	private Handler mHandler = new Handler();
	private TextView mTextViewNumber;
	private StateReceiver mReceiver;
	private MediaPlayer mMediaPlayer;
	private AudioManager mAudioManager;
	private String mCallId = "";
	DisplayImageOptions options;
	UpdateBroadcastReceiver mUpdateBroadcastReceiver;
	CallStateReceiver2 mCallStateReceiver;
	private ImageButton converse_call_mute;
	private ImageButton converse_call_video;
	private ImageButton converse_call_speaker;
	private ImageButton converse_call_switch;

	private boolean open_headset=false;
	private boolean closeVideo = false;
	private boolean isAnswer = false;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_out_call);
		if (!UCSService.isConnected()) {
			startService(new Intent(this, CallConnectionService.class));
		}

		Parameters.isOutCalling = true;
		options = new DisplayImageOptions.Builder()
		.displayer(new PinterestCircleBitmapDisplayer(getResources().getDimensionPixelSize(R.dimen.corners_avatar)))
		.showImageOnFail(R.drawable.bg_share_header)
		.showImageOnLoading(R.drawable.bg_share_header)
		.cacheInMemory(true)
		.cacheOnDisk(true)
		.considerExifParams(true)
		.bitmapConfig(Bitmap.Config.RGB_565)
		.build();

		//		com.yzx.api.UCSCall


		mAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
		mMediaPlayer = MediaPlayer.create(this, R.raw.dudu);
		mReceiver = new StateReceiver();
		IntentFilter mFilter = new IntentFilter();
		mFilter.addAction(ACTION_QUERY_USER_STATE);
		registerReceiver(mReceiver, mFilter);
		mTextView = findView(R.id.title);
		mTextViewState = (TextView) findViewById(R.id.textview_state);

		mImageView = (ImageView) findViewById(R.id.iv);
		mTextViewNumber = findView(R.id.number);
		mTextViewlevel = (TextView) findViewById(R.id.level);
		mTextView.setText(R.string.calling);
		mSuperFriends = getIntent().getParcelableExtra(KEY_DATA);
		
		super.setmSuperFriends(mSuperFriends);
		ContactsBaseBean.setupDoubleLineContactsView(
				findViewById(R.id.contacts_area), mSuperFriends);
		try {
			if(mSuperFriends == null) {
				Toast.makeText(getApplicationContext(), "用户可能不存在，请重试", Toast.LENGTH_LONG).show();
			}
			mTextViewlevel.setText(getLevel(mSuperFriends.getLevel()));
		} catch(Exception e) {

		}
		// mTextViewNumber.setText(ContactsDialPadAdapter.replaceTextColor(
		// mSuperFriends.getPhone(), mSuperFriends.getPhone(),
		// mSuperFriends));
		try {

			if (mSuperFriends.getSucolor() == 0) {
				mTextViewNumber.setText(mSuperFriends.getWhiteSuperNumber());
			} else {
				mTextViewNumber.setText(mSuperFriends.getSuperNumber());
				// mTextViewNumber.setText(ContactsDialPadAdapter
				// .replaceTextColor(mFriends.getPhone(),
				// mFriends.getPhone(), mFriends));
			}	
		} catch(NullPointerException e) {

		}

		setLevelColor(mSuperFriends.getSucolor(), mTextView, mTextViewNumber);
		refreshView(mSuperFriends);
		dial();
		//		UCSCall.dial(getActivity(), CallType.VOIP, mSuperFriends.getVo_id());
		// UCSCall.startCallRinging("dialling_tone.pcm");
		// mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
		mAudioManager.setSpeakerphoneOn(false);
		UCSCall.setSpeakerphone(false);
		mMediaPlayer.setLooping(true);
		mMediaPlayer.setOnPreparedListener(new OnPreparedListener() {
			@Override
			public void onPrepared(MediaPlayer mp) {
				// TODO Auto-generated method stub
				// mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
				mMediaPlayer.start();
			}
		});
		try {
			mMediaPlayer.prepare();
		} catch (IllegalStateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		addCallHistory();

		mHandlerSendBroadcast.sendEmptyMessageDelayed(0, 3000);
		//		
		IntentFilter filter = new IntentFilter();
		filter.addAction(ACTION_CONNECTION_SUCCESS2);
		mUpdateBroadcastReceiver = new UpdateBroadcastReceiver();
		registerReceiver(mUpdateBroadcastReceiver, filter);

		mCallStateReceiver = new CallStateReceiver2();
		IntentFilter ift = new IntentFilter();
		ift.addAction(ACTION_DIAL_STATE);
		registerReceiver(mCallStateReceiver, ift);



		// ***************************

		converse_call_mute = (ImageButton) findViewById(R.id.converse_call_mute);
		converse_call_video = (ImageButton) findViewById(R.id.converse_call_video);
		converse_call_speaker = (ImageButton) findViewById(R.id.converse_call_speaker);
		converse_call_switch = (ImageButton) findViewById(R.id.converse_call_switch);

		//静音
		converse_call_mute.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				if(UCSCall.isMicMute()){
					converse_call_mute.setBackgroundResource(R.drawable.converse_mute);
				}else{
					converse_call_mute.setBackgroundResource(R.drawable.converse_mute_down);
				}
				UCSCall.setMicMute(!UCSCall.isMicMute());
			}
		});

		//摄像头开关
		converse_call_video.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				if(closeVideo){
					//开启自己的摄像头
					closeVideo = false;
					converse_call_video.setBackgroundResource(R.drawable.converse_video);
				}else{
					//关闭自己的摄像头
					closeVideo = true;
					converse_call_video.setBackgroundResource(R.drawable.converse_video_down);
				}
			}
		});

		//扬声器
		converse_call_speaker.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				if(UCSCall.isSpeakerphoneOn()){
					converse_call_speaker.setBackgroundResource(R.drawable.converse_speaker);
				}else{
					converse_call_speaker.setBackgroundResource(R.drawable.converse_speaker_down);
				}
				UCSCall.setSpeakerphone(!UCSCall.isSpeakerphoneOn());
			}
		});

/*		//切换摄像头
		converse_call_switch.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				CustomLog.e("当前摄像头："+UCSCall.getCurrentCameraIndex());
				if(UCSCall.getCurrentCameraIndex()==0){
					UCSCall.switchCameraDevice(1);
				}else{
					UCSCall.switchCameraDevice(0);
				}
			}
		});*/
		/*	//接通
				video_call_answer.setOnClickListener(new View.OnClickListener() {
					@Override
					public void onClick(View v) {
//						CustomLog.v(DfineAction.TAG_TCP,"接通电话");
						UCSCall.stopRinging();
						UCSCall.answer("");
						UCSCall.setSpeakerphone(false);
					}
				});

				//挂断
				video_call_hangup.setOnClickListener(new View.OnClickListener() {
					@Override
					public void onClick(View v) {
					UCSCall.stopRinging();
					UCSCall.hangUp("");
					new Handler().postDelayed(new Runnable() {
						@Override
						public void run() {
							OutCallActivity.this.finish();
						}
					}, 1500);
					}
				});*/

		/*remotelayout = (LinearLayout) findViewById(R.id.remotelayout);			
		locallayout = (LinearLayout) findViewById(R.id.locallayout);
		UCSCall.initCameraConfig(OutCallActivity.this, remotelayout, locallayout);*/


		/*IntentFilter ift2 = new IntentFilter();
		ift2.addAction(UIDfineAction.ACTION_DIAL_STATE);
		ift2.addAction(UIDfineAction.ACTION_ANSWER);
		ift2.addAction(UIDfineAction.ACTION_CALL_TIME);
		ift2.addAction(UIDfineAction.ACTION_NETWORK_STATE);
		ift2.addAction("android.intent.action.HEADSET_PLUG");
		registerReceiver(br, ift2);*/
/*		UCSCall.refreshCamera(UCSCameraType.LOCALCAMERA);
		mHandlerCamera.sendEmptyMessageDelayed(0, 1000);

		//				LoginConfig.saveCurrentCall(VideoConverseActivity.this,2);
		//默认一开始使用前摄像头 0：后摄像头,1:前摄像头
		UCSCall.switchCameraDevice(1);*/
//		sendCallPush();
	}

	//不用这个启动会很耗时间	
	Handler mHandlerSendBroadcast = new Handler() {

		@Override
		public void handleMessage(Message msg) {
			// TODO Auto-generated method stub
			super.handleMessage(msg);
			sendBroadcast(new Intent(Constants.ACTION_RECEIVE_MSG2));
		}

	};

	private void dial() {
		//		if (phoneNumber != null && phoneNumber.length() > 0) {
		sendCallPush();
		
		//		}
	}



	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
//		mHandlerCamera.sendEmptyMessageDelayed(0, 1000);

	}

	@Override
	protected void onRestart() {
//		mHandlerCamera.sendEmptyMessageDelayed(0, 1000);
		super.onRestart();
	}

	@Override
	protected void onPause() {
//		mHandlerCamera.sendEmptyMessageDelayed(1, 1000);
		super.onPause();
	}

	private int mCount = 45;
	private Runnable mUserState = new Runnable() {

		@Override
		public void run() {
			// TODO Auto-generated method stub
			mCount--;
			if (mCount == 0) {
				hangUp(findView(R.id.hang_up));
				showToast(R.string.call_time_out);
			} else {
				mHandler.postDelayed(mUserState, 1000);
			}
		}
	};

	private void addCallHistory() {
		JSONObject json = getBaseParams(getActivity());
		try {
			json.put("i_calluserid", mSuperFriends.getUserid());
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		mHttpClient.post(FUNCTION_ADD_CALL_HISTORY, json, new MyAjaxCallBack() {

			@Override
			public void onReceiveError(String msg, String errorCode) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onReceiveData(String data, String msg) {
				// TODO Auto-generated method stub
				try {
					sendBroadcast(new Intent(ACTION_UPDATE_CALL));
					JSONObject json = new JSONObject(data.substring(1,
							data.length() - 1));
					mCallId = json.getString("callid");
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		});
	}

	private void updateCallHistory() {
		JSONObject json = getBaseParams(getActivity());
		try {
			json.put("i_callid", mCallId);
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		mHttpClient.post(FUNCTION_CALL_RECEIVE, json, new MyAjaxCallBack() {

			@Override
			public void onReceiveError(String msg, String errorCode) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onReceiveData(String data, String msg) {
				// TODO Auto-generated method stub

			}
		});
	}

	private void startCountForUserState() {
		// mHandler.postDelayed(mUserState, 45*1000);
	}

	public void hangUp(View v) {
		v.setEnabled(false);
		UCSCall.hangUp("");
		try {
			if (mMediaPlayer.isPlaying()) {
				mMediaPlayer.stop();
				mMediaPlayer.release();
			}
		} catch (IllegalStateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		addCallTime();
		stopCountUp();
		mHandler.postDelayed(new Runnable() {

			@Override
			public void run() {
				// TODO Auto-generated method stub
				finish();
			}
		}, 1500);
	}

	@Override
	public void onHangUp() {
		// TODO Auto-generated method stub
		try {
			if(stateint == 0) {
				//				mTextViewState.setText("已挂断");
				mTextViewState.setText("对方正忙");
			} else if(stateint == 1) {
				mTextViewState.setText("对方拒绝接听");
			} else if(stateint == 2) {
				mTextViewState.setText("已挂断");
			}
			if (mMediaPlayer.isPlaying()) {
				mMediaPlayer.stop();
				mMediaPlayer.release();
			}
		} catch (IllegalStateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	@Override
	public void handFree(View v) {
		// TODO Auto-generated method stub
		super.handFree(v);
		mAudioManager.setSpeakerphoneOn(v.isSelected());
	}

	@Override
	public void handleOffLineUser() {
		// TODO Auto-generated method stub
		super.handleOffLineUser();
		startCountForUserState();
//		sendCallPush();

		startQueryUserState();
	}



	private void sendCallPush() {
		Session mSession = Session.getSession();
		mSession.SendPushMsg(getApplicationContext(), getUser(getActivity()).getNick_name() +"给您打了电话" , 2,  mSuperFriends.getPhone(), getUser(getActivity()).getNick_name() +"给您打了电话" ,  new ResultReceiver<Integer>() {

			@Override
			public void onResult(boolean last, Integer args) {
//				if(args == 1) {
				// TODO Auto-generated method stub
				UCSCall.dial(getActivity(), CallType.VOIP, mSuperFriends.getVo_id());
				UCSCall.setSpeakerphone(false);
				sendBroadcast(new Intent(UIDfineAction.ACTION_DIAL).putExtra(UIDfineAction.CALL_UID, mSuperFriends.getVo_id()).putExtra("type",1));
			/*	} else {
					mTextView.setText("对方不在线");
					UCSCall.stopRinging();
					UCSCall.stopCallRinging();
					new Handler().postDelayed(new Runnable() {
						@Override
						public void run() {
							OutCallActivity.this.finish();
						}
					}, 1000);
				}*/
			}

		});
		
		/*JSONObject json = new JSONObject();
		try {
			json.put("phone", getUser(getActivity()).getPhone());
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		mHttpClient.sendPushMsg(
				2,
				getString(R.string.someone_makes_a_call, getUser(getActivity())
						.getNick_name()), json.toString(), mSuperFriends
						.getPhone());*/
	}

	private void startQueryUserState() {
		mHandler.post(mQueryRunnable);
	}

	private Runnable mQueryRunnable = new Runnable() {

		@Override
		public void run() {
			// TODO Auto-generated method stub
			UCSMessage.queryUserState(ClientType.PHONE,
					mSuperFriends.getPhone());
		}
	};
	private ImageView mImageView;
	private TextView mTextViewState;
	private TextView mTextViewlevel;

	public void onTimeOut() {
		handleOffLineUser();
	};

	@Override
	public void onAnswer() {
		// TODO Auto-generated method stub
		super.onAnswer();
		mTextView.setText(R.string.call_busy);
		mTextViewState.setText(R.string.call_busy);
		addFollow();
		startCountUp();
		// UCSCall.stopCallRinging();
		startListenSensor();
		try {
			if (mMediaPlayer.isPlaying()) {
				mMediaPlayer.stop();
				mMediaPlayer.release();
			}
		} catch (IllegalStateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		updateCallHistory();
	}

	/**
	 * 拨打电话互粉
	 */
	private void addFollow() {
		JSONObject json = getBaseParams(getActivity());
		try {
			json.put("i_otherid",
					mSuperFriends == null ? 0 : mSuperFriends.getUserid());
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		mHttpClient.post(FUNCTION_ADD_HUFEN, json, new MyAjaxCallBack() {

			@Override
			public void onReceiveError(String msg, String errorCode) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onReceiveData(String data, String msg) {
				// TODO Auto-generated method stub

			}
		});
	}

	@Override
	public void onBackPressed() {
		// TODO Auto-generated method stub
		// super.onBackPressed();
	}

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		Parameters.isOutCalling = false;
		unregisterReceiver(mReceiver);
		mHandler.removeCallbacks(mQueryRunnable);
		mHandler.removeCallbacks(mUserState);
		// UCSCall.stopCallRinging();
		try {
			if (mMediaPlayer.isPlaying()) {
				mMediaPlayer.stop();
				mMediaPlayer.release();
			}
		} catch (IllegalStateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if(mUpdateBroadcastReceiver != null) {
			getActivity().unregisterReceiver(mUpdateBroadcastReceiver);
			mUpdateBroadcastReceiver = null;
		}

		if(mCallStateReceiver != null) {
			getActivity().unregisterReceiver(mCallStateReceiver);
			mCallStateReceiver = null;

		}  

/*		if(br != null) {
			getActivity().unregisterReceiver(br);
			br = null;

		}*/
	}

	public class StateReceiver extends BroadcastReceiver {

		@Override
		public void onReceive(Context context, Intent intent) {
			// TODO Auto-generated method stub
			if (ACTION_QUERY_USER_STATE.equals(intent.getAction())) {
				UcsStatus status = CallConnectionService.mUserStateMap
						.get(mSuperFriends.getVo_id());
				if (status != null) {
					if (status.isOnline()) {
						setTextViewText(R.id.title, getString(R.string.calling));
						UCSCall.dial(getActivity(), CallType.VOIP,
								mSuperFriends.getVo_id());
						mHandler.removeCallbacks(mQueryRunnable);
					} else {
						setTextViewText(R.id.title, getString(R.string.calling));
						mHandler.postDelayed(mQueryRunnable, 1500);
					}
				}
				mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
			}
		}
	}
	class UpdateBroadcastReceiver extends BroadcastReceiver {

		public UpdateBroadcastReceiver() {

		}

		@Override
		public void onReceive(Context context, Intent intent) {
			// TODO Auto-generated method stub
			mTextViewState.setText("正在响铃");
			Log.i("tag2", "successbroadcast");
		}

	}

	void setLevelColor(int level,TextView tvUserName, TextView tvPhone, TextView tvLevel) {
		try {

			if(level == 0) {
				tvPhone.setTextColor(getResources().getColor(R.color.white));
				tvUserName.setTextColor(getResources().getColor(R.color.white));
				tvLevel.setTextColor(getResources().getColor(R.color.white));

			} else if(level == 1) {
				tvPhone.setTextColor(getResources().getColor(R.color.level_or));
				tvUserName.setTextColor(getResources().getColor(R.color.level_or));
				tvLevel.setTextColor(getResources().getColor(R.color.level_or));
			} else {
				tvPhone.setTextColor(getResources().getColor(R.color.level_red));
				tvUserName.setTextColor(getResources().getColor(R.color.level_red));
				tvLevel.setTextColor(getResources().getColor(R.color.level_red));
			}
		} catch(NullPointerException e) {

		}
	}
	String getLevel(int level){
		String levelS = null;
		switch(level) {
		case 1:levelS="新诞生";break;
		case 2:levelS="吃奶尿床";break;
		case 3:levelS="断奶吃饭";break;
		case 4:levelS="说学走";break;
		case 5:levelS="幼儿园";break;
		case 6:levelS="小学生";break;
		case 7:levelS="初中生";break;
		case 8:levelS="高中生";break;
		case 9:levelS="大学生";break;
		case 10:levelS="硕士";break;
		default:levelS="博士";break;
		}
		return levelS;
	}

	/**
	 * 监听云之讯返回的状态码
	 * 
	 * @see com.yunfeng.supercall.service.CallConnectionService#onDialFailed(String,
	 *      com.yzx.listenerInterface.UcsReason)
	 * @author 洋
	 * 
	 */
	public class CallStateReceiver2 extends BroadcastReceiver {
		@Override
		public void onReceive(Context context, Intent intent) {
			int code = intent.getIntExtra("state", -1);
			if(300247 == code) {
				mTextViewState.setText("对方正在响铃");
			}
		}
	}
	private BroadcastReceiver br = new BroadcastReceiver() {
		@Override
		public void onReceive(Context context, Intent intent) {
			if(intent.getAction().equals(UIDfineAction.ACTION_DIAL_STATE)){
				int state = intent.getIntExtra("state", 0);
				if(UIDfineAction.dialState.keySet().contains(state)){
					//				converse_information.setText(UIDfineAction.dialState.get(state));
				}
				if(state == UCSCall.CALL_VOIP_RINGING_180){
					UCSCall.startCallRinging("dialling_tone.pcm");
				}else {
					UCSCall.stopRinging();
					UCSCall.stopCallRinging();
					new Handler().postDelayed(new Runnable() {
						@Override
						public void run() {
							OutCallActivity.this.finish();
						}
					}, 1000);
				}
			}else if(intent.getAction().equals(UIDfineAction.ACTION_ANSWER)){
				isAnswer=true;
				AudioManager mAudioManager = ((AudioManager) getSystemService(Context.AUDIO_SERVICE));
				if(mAudioManager.isWiredHeadsetOn()){
					converse_call_speaker.setBackgroundResource(R.drawable.converse_speaker);
					UCSCall.setSpeakerphone(false);
				}else {
					converse_call_speaker.setBackgroundResource(R.drawable.converse_speaker_down);
					UCSCall.setSpeakerphone(true);
				}
				UCSCall.stopCallRinging();
				UCSCall.stopRinging();
				/*locallayout.setVisibility(View.VISIBLE);
				remotelayout.setVisibility(View.VISIBLE);*/
				converse_call_mute.setVisibility(View.VISIBLE);
				converse_call_video.setVisibility(View.VISIBLE);
				converse_call_speaker.setVisibility(View.VISIBLE);
				converse_call_switch.setVisibility(View.VISIBLE);
				//        	video_call_answer.setVisibility(View.GONE);
				open_headset = true;
				//刷新远程摄像，重要，一定要加这个
//				mHandlerCamera.sendEmptyMessageDelayed(2, 1000);
				//        	sendBroadcast(new Intent(UIDfineAction.ACTION_START_TIME));
			}/*else if(intent.getAction().equals(UIDfineAction.ACTION_CALL_TIME)){
			String timer = intent.getStringExtra("timer");
			if(converse_information != null){
				converse_information.setText(timer);
			}
		}*//*else if(intent.getAction().equals(UIDfineAction.ACTION_NETWORK_STATE)){*/
			/*switch (intent.getIntExtra("state", 0)) {
			case 0:
				converse_network.setText("网络质量一般");
				break;
			case 1:
				converse_network.setText("网络质量好");
				break;
			case 2:
				converse_network.setText("网络质量差");
				break;
			default:
				if(!isAnswer){
					converse_information.setText("无网络");
					UCSCall.stopRinging();
					UCSCall.stopCallRinging();
					new Handler().postDelayed(new Runnable() {
						@Override
						public void run() {
							VideoConverseActivity.this.finish();
						}
					}, 1000);
					break;
				}
			}*/
			/*}*/else if(intent.getAction().equals("android.intent.action.HEADSET_PLUG")){
				//发现个别手机会接通电话前收到这个广播并把扬声器打开了，所以open_headset作为判断必须接通后再接收耳机插拔广播才有效
				if(intent.getIntExtra("state", 0) == 1 && open_headset){
					//				CustomLog.e(DfineAction.TAG_TCP,"Speaker false");
					converse_call_speaker.setBackgroundResource(R.drawable.converse_speaker);
					UCSCall.setSpeakerphone(false);
				}else if(intent.getIntExtra("state", 0) == 0 && open_headset){
					//            	CustomLog.e(DfineAction.TAG_TCP,"Speaker true");
					converse_call_speaker.setBackgroundResource(R.drawable.converse_speaker_down);
					UCSCall.setSpeakerphone(true);
				}   
			}
		}
	};

/*	private Handler mHandlerCamera = new Handler(){
		@Override
		public void dispatchMessage(Message msg) {
			switch(msg.what){
			case 0:
				converse_call_video.setBackgroundResource(R.drawable.converse_video);
				UCSCall.refreshCamera(UCSCameraType.ALL);
				break;
			case 1:
				UCSCall.closeCamera(UCSCameraType.ALL);
				break;
			case 2:
				converse_call_video.setBackgroundResource(R.drawable.converse_video);
				UCSCall.refreshCamera(UCSCameraType.REMOTECAMERA);
				break;
			}
		}
	};*/

}

